﻿using EmoneyWeiXinEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using EmoneyWeiXinCommon;

namespace EmoneyWeiXinDAL
{
    public class WatchVideoRecordDAL
    {
        public int Insert(WatchVideoRecordEntity entity)
        {
            string sql = @"INSERT INTO WatchVideoRecord VALUES(@videoId,@openid,@nickName,@className,@watchTime);
                           if not exists(SELECT 1 FROM UserGroupRel WHERE OPENID=@openid AND GROUPID=@groupId)
                           INSERT INTO UserGroupRel(WEIXINID,GROUPID,OPENID,UPDATETIME) VALUES(@weixinId,@groupId,@openid,GETDATE())";
            SqlParameter[] paras = 
            {
              new SqlParameter("@videoId",entity.videoId),
              new SqlParameter("@openid",entity.openid),
              new SqlParameter("@nickName",entity.nickName),
              new SqlParameter("@className",entity.className),
              new SqlParameter("@watchTime",entity.watchTime),
              new SqlParameter("@weixinId",entity.weixinId),
              new SqlParameter("@groupId",ConstName.watchVideoGroupId)
            };
            return SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, System.Data.CommandType.Text, sql, paras);

        }
    }
}
